<!-- 进程管控 -->
<template>
<div>
  <el-row>
    <div style="display:flex;justify-content:space-between;">
        <div>
          <el-button type="primary" @click="add">添加白名单目录</el-button>
          <span style="color:#d2d7e3;font-size:25px;margin-top:10px;padding-left:10px;"> 
            <el-tooltip class="item" effect="dark" placement="right">
              <i class="el-icon-question"></i> 
              <div style="width: 420px;" slot="content">运行信任的签名证书程序，将不会上送检测，也不会进行进程阻断</div>
            </el-tooltip>
          </span>
        </div>
      </div>
    <el-table stripe border :data="tableData" row-key="Name" style="width: 100%; margin-top: 15px">
      <el-table-column label="序号"  width="60" type="index" :index='(index)=>{return (index + 1) + (this.pageNum - 1)*this.pageSize}'> </el-table-column>
      <el-table-column label="目录名称" prop="Name"  show-overflow-tooltip></el-table-column>
      <el-table-column label="操作" fixed="right" width="120px">
        <template slot-scope="scope">
          <el-button size="mini" type="danger" @click="deleteOnclick(scope.row, scope.$index)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-row>
  <el-dialog
      :close-on-click-modal="false"
      :close-on-press-escape=false
      title="添加白名单目录"
      :visible.sync="auditdialog"
      v-el-drag-dialog
      width="800px">
      <el-form label-width="130px" :model="auditForm" ref="auditForm">
        <el-row >
          <el-col :xs="24" :sm="24" :lg="24">
            <el-form-item label='目录名称：' prop="Name">
              <el-select style="width:100%" 
                v-model="auditForm.Name" 
                filterable 
                allow-create 
                :default-first-option="true" 
                @input="handleInput"
                placeholder="请选择白名单目录">
                <el-option v-for="(item, index) in catalogueList" :key="index" :label="item.path" :value="item.path">
                  <span style="float: left">{{ item.path }}</span>
                  <span style="float: right; color: #8492a6; font-size: 13px">{{ item.desc }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form> 
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submit()">确 定</el-button>
        <el-button type="info" @click="auditdialog = false">取 消</el-button>
      </span>
    </el-dialog>
</div>
</template>

<script>
import { connrequest } from '@/api/firstPage'
import elDragDialog from '@/directive/el-drag-dialog' // base on element-ui
export default {
directives: { elDragDialog },
data() {
return {
  pageNum: 1,
  pageSize: 10,
  tableData: [],
  auditForm:{},
  auditdialog: false,
  catalogueList: []
}
},
watch:{
  
},
//生命周期 - 创建完成（访问当前this实例）
created() {
  this.getData()
  this.GetWhiteDirCandidate()
},
//生命周期 - 挂载完成（访问DOM元素）
mounted() {
},
methods: {
  selectBlur(value) {
    if (value) {
      this.$set(this.auditForm, 'Name', value);
    }
  },
  handleInput(value) {
    // 允许输入的字符: 除去<>*?|"的其他字符
    const filteredValue = value.replace(/[<>*?|""]/g, "");
    this.$set(this.auditForm, 'Name', filteredValue);
  },
  async GetWhiteDirCandidate (){
    const res = await connrequest('GetWhiteDirCandidate')
    this.catalogueList = res.Data
  },
  async getData(){
    const data = {
      Filter: {
        FileName: 'param_proc_white_dir.json'
      }
    }
    const res = await connrequest('GetUICommonParam', data)
    res.Data = res.Data.filter(d=>d)
    let arr = []
    res.Data.map(item => {
      arr.push({Name: item})
    })
    this.tableData = arr
  },
  add(){
    this.auditForm = {Name: this.catalogueList?.[0]?.path}
    this.auditdialog = true
  },
  async submit(){
    if(!this.auditForm.Name){
      this.$message.error('目录名称不能为空')
      return false
    }
    let arr = [...this.tableData]
    arr.push({Name: this.auditForm.Name})
    arr = arr.map(item => item.Name)
    const data = {
      Filter: {
        FileName: 'param_proc_white_dir.json'
      },
      Data: arr
    }
    const res = await connrequest('SetUICommonParam', data)
    if(res.Status.StatusCode === 0){
      this.$message({
        type: 'success',
        message: `添加成功!`
      });
      this.getData()
    }
    this.auditdialog = false
  },
  deleteOnclick(row, index){
    this.$confirm(`确定删除?`, '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    }).then(async () => {
      let arr = [...this.tableData]
      arr.splice(index, 1)
      arr = arr.map(item => item.Name)
      const data = {
          Filter: {
            FileName: 'param_proc_white_dir.json'
          },
          Data: arr
        }
      const res = await connrequest('SetUICommonParam', data)
      if(res.Status.StatusCode === 0){
        this.$message({
          type: 'success',
          message: `删除成功!`
        });
        this.getData()
      }
    }).catch(() => {
      this.$message({
        type: 'info',
        message: '已取消删除'
      });          
    });
  }
}
}
</script>